// pages/profile/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(wx.getStorageSync('login')) {
      wx.redirectTo({
        url: '/pages/canteen/index/index',
      })
    }
  },
  goAll:function(){
    wx.navigateTo({
      url: '/pages/order/list/list',
    })
  },
  goWindow:function() {
    wx.navigateTo({
      url: '/pages/canteen/login/login'
    })
  },
  goUser(){
    wx.navigateTo({
      url: '/pages/prefer/user/user'
    })
  },
  goPrefer(){
    wx.getStorage({
      key: 'myData',
      success (res) {
        var student_id = res.data.student_id;
        const db = wx.cloud.database()
        db.collection('student').where({
          student_id:student_id
        })
        .get({
          success: function(res) {
            // res.data 是包含以上定义的两条记录的数组
            console.log(res.data[0].student_status)
            if(res.data[0].student_status==1){
              wx.navigateTo({
                url: '/pages/prefer/prefer_succeed/prefer_succeed',
              })
            }else if(res.data[0].student_status==2){
              wx.navigateTo({
                url: '/pages/prefer/prefer_fail/prefer_fail',
              })
            
            }else if(res.data[0].student_status==0){
              wx.navigateTo({
                url: '/pages/prefer/succeed/succeed',
              })
            }else{
              wx.navigateTo({
                url: '/pages/prefer/push/push',
              })
            }
          }
        })
       
      }
    })
    // wx.navigateTo({
    //   url: '/pages/prefer/push/push',
    // })
  }
})